﻿#region Copyright

//  ======================================================
//      Copyright (c) 2011 Toulr All rights reserved.
//     
//      The use and distribution terms for this software are contained in the file
//      named license.txt, which can be found in the root of this distribution.
//      By using this software in any fashion, you are agreeing to be bound by the
//      terms of this license.
//     
//     You must not remove this notice, or any other, from this software.
//  ======================================================

#endregion

#region Using Namespaces

using System;
using Toulr.Util.Logging;
using Toulr.Util.Net.Email;
using Toulr.Util.Text;

#endregion

namespace Toulr.Core
{
    public class Utility
    {
        private static readonly ILogger Logger = LogHelper.LogFactoy.Create("Utility");

        /// <summary>
        ///   Sends the mail.
        /// </summary>
        /// <param name = "email">The email.</param>
        /// <param name = "message">The message.</param>
        /// <returns></returns>
        /// Author: James Cheung
        /// MachineName: JAMESCHEUNG-PC
        /// DateTime: 2011/5/14 10:51
        public static bool SendMail(Message message)
        {
            try
            {
                //发送 邮件
                var smtpSender = new SmtpSender(Resource.Resource.Email_SMTP)
                                     {
                                         UserName = Resource.Resource.Email_UserName,
                                         Password =
                                             Encoding.Rc2Decrypt(Resource.Resource.Email_Password, Resource.Resource.KEY,
                                                                 Resource.Resource.IV)
                                     };
                message.From = Resource.Resource.Email_Source;
                message.Format = Format.Html;
                smtpSender.Send(message);
                return true;
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message, ex);
                return false;
            }
        }
    }
}